<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="/build/css/base.css"/>
	<link rel="stylesheet" type="text/css" href="/build/css/main.css">
	<script src="/build/public/vue.js" charset="utf-8"></script>
	<script src="/build/public/vue-resource.js" charset="utf-8"></script>
	<script src="/build/js/jquery.min.js"></script>
	<script src="/build/js/global.js"></script>
	<style>
		html,body{
		  width: 100%;
		  height:100%;
		}
	</style>
</head>
<body>
	<div id="container" class="login-bg">
		<div class="sign-href">
			<a href="/index.html">随便看看>></a>
		</div>
		<div class="logo" style="height:130px;">
		</div>
		<div class="login-input" id="mobile">
			<span class="login-text">
				<span class="iconfont iconfontBig">&#xe613;</span>
				手机：
			</span>
			<input v-model="username" type="tel" @keyup.enter="login" maxlength="11" class="mobile" id="mobileInput">
		</div>
		<div class="login-input" id="password">
			<span class="login-text">
				<span class="iconfont">&#xe62e;</span>
				密码：
			</span>
			<input v-model="password" type="password" @keyup.enter="login" maxlength="18" class="password" id="passwordInput">
		</div>
		<div class="login-btn">
			<button @click="login" class="sign-in">登录</button>
			<button @click="exitLogin" class="sign-in resgiter">注册</button>
		</div>
		<div class="forget-pass">
			<span class="forget-l" id="checkbox">
				<img src="../../build/images/select.png" alt="" width="20" height="20" class="iconfont1 checkbox"><img src="../../build/images/noselect.png" alt="" width="20" height="20" class="iconfont2 checkbox" style="display:none;">记住密码
			</span>
			<a href="forgetPass.html" class="forget-r">
				忘记密码？
			</a>
		</div>
		<div class="other-login">
			<i></i>
			<span>其他方式登录</span>
			<i class="line-r"></i>
			<b><span class="iconfont" @click='invite' style="">&#xe628;</span></b>
		</div>
	</div>
<script src="/build/js/config.js" charset="utf-8"></script>
<script src="/build/js/common.js" charset="utf-8"></script>
<script type="text/javascript">
var vm = new Vue({
	el:"#container",
	data:{
		username:'',
		password:'',
		dataUrl:'',
	},
	mounted:function(){
		this.$nextTick(function(){
			vm.isLogin();
			var mobile=window.localStorage.getItem('mobile');
			var password=window.localStorage.getItem('password');
			if(mobile && password){
				if($('.iconfont2').css('display')=='none'){
					vm.username=mobile;
					vm.password=password;
				}
			}
			var mobileId=document.getElementById('mobile');
			var passwordId=document.getElementById('password');
			var mobileInput=document.getElementById('mobileInput');
			var passwordInput=document.getElementById('passwordInput');
			mobileId.addEventListener('click', function(){
				mobileInput.focus();
			});
			passwordId.addEventListener('click', function(){
				passwordInput.focus();
			});

		})
	},
	methods:{
		login:function(){
			var $this = this;
			if($('.iconfont2').css('display')=='none'){
				post('/user/login',{
					mobile:this.username,
					password:this.password
				},function(res){
					window.localStorage.setItem('mobile',vm.username);
					window.localStorage.setItem('password',vm.password);
					window.localStorage.setItem(siteTokenKey,res.data.token)
					toast(res.data.name+'登录成功');
					setTimeout(function(){
						window.location.href='/index.html'
					},1500)
				},function(res){
					toast(res.error);
				});
			}else{
				post('/user/login',{
					mobile:this.username,
					password:this.password
				},function(res){
					toast(res.data.name+'登录成功');
					setTimeout(function(){
						window.location.href='/index.html'
					},1500)
				});
			}
		},
		isLogin:function(){
			var token = window.localStorage.getItem(siteTokenKey);
		},
		exitLogin:function(){
			window.location.href='register.html'
		},
		invite:function(){
			get('/weiXinOAuth/advisor/code',{},function(res){
				window.location.href = res.data;
			})
		},
	}
})
</script>
</body>
</html>
